<#if needHeadAndBottom != 'no'>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyleTree.html">
    <script src="${ctx}/formStatic/verify.js"></script>
    <script src="${ctx}/formStatic/form/form.js"></script>
    <script src="${ctx}/formStatic/form/CommonDialog.js" type="text/javascript"></script>
</head>
<body>
</#if>
<div class="layui-form" style="height:88%;overflow: auto" lay-filter="formData" id="formDefEdit">
    <div class="layui-btn-container" style="position: absolute;left: 46%;bottom: 0;">
        <#if hideBtn != 'yes'>
        <button class="layui-btn" lay-submit lay-filter="dataTemplateForm">保存</button>
        <button class="layui-btn layui-btn-danger return">取消</button>
        </#if>
    </div>
    <input type="hidden" name="formData" id="formData"/>
    <input type="hidden" id="id" name="id" value="${id}"/>
    <input id='tableId' name='tableId' type='hidden'/>
    <input id='alias' name='alias' type='hidden'/>
    <div class="formPreview templateAddEdit">
    </div>
</div>

<script>
    var formKey = '${formKey}';
    var needVer = '${needVer}';
    var id = '${id}';
    var procDefId = '${procDefId}';
    var nodeId = '${nodeId}';
    var jsPreScript = '';
    var jsAfterScript = '';
    var needHeadAndBottom = '${needHeadAndBottom}';
    //是否允许修改密级，表单嵌入在流程处理页面不允许修改密级
    var enableEditPrivacy = '${enableEditPrivacy}';

    <#if needHeadAndBottom != 'no'>
        layui.config({
            base: serverPath.formPath + staticPath.formPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index', 'setter', 'ice', 'form', 'element', 'layer', 'slider', 'colorpicker', 'form', 'totalFilter', 'propsHandle', 'commons'], function () {
    <#else>
        layui.use(['setter', 'ice', 'form', 'element', 'layer', 'slider', 'colorpicker', 'form', 'table', 'totalFilter', 'propsHandle','commons'], function () {
    </#if>
            var $ = layui.$,
            setter = layui.setter,
            layer = layui.layer,
            ice = layui.ice,
            propsHandle = layui.propsHandle,
            form = layui.form,
            commons = layui.commons,
            defProps = {
                viewMould: serverPath.formPath + '/form/formDef/view/formDesign/moulds/',
                initCss: [
                    'style/forms/grid/grid1',
                    'style/forms/grid/grid2',
                    'style/forms/grid/grid3',
                    'style/forms/template/tag',
                    'style/forms/template/text',
                    'style/forms/template/table',
                    'style/forms/template/textArea',
                    'style/forms/template/radioOption',
                    'style/forms/template/date',
                    'style/forms/template/button',
                    'style/forms/template/uploadFile',
                    'style/forms/template/richText',
                    'style/forms/template/select',
                    'style/forms/template/checkOption',
                    'style/forms/template/dataLexi',
                    'style/forms/template/uploadImg',
                    'style/forms/template/selector',
                    'style/forms/formDevise',
                    'style/forms/dragLay',
                    'style/forms/formPreview'
                ],
                formAreaInfo: 'html',
                temDate: '.temDate',
                uploadFileBtn: '.uploadFileBtn',
                uploadImgBtn: '.uploadImgBtn',
                richTextArea: '.richTextArea',
                selectInput: '.selectInput',
                radioOptionCont: '.radioOptionCont',
                dataLexiTree: '.dataLexiTree',
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle()
        ;
        ice.loadCss(defProps.initCss);

        var permission;
        var formTable;
        $.ajax({
            url: serverPath.formPath + setter.formLinkPath + 'dataTemplate/editData?alias=' + formKey,
            dataType: 'json',
            data: {"id": id, "procDefId": procDefId, "nodeId": nodeId},
            success: function (result) {
                if (commons._filterRecord(result)) {
                    $(".templateAddEdit").append(result.data.formDef.html);

                    $(".temSpace .dataLexiVal").each(function(){
                        if($(this).attr("dictype")==="0"){
                            var verify = $(this).attr("lay-verify");
                            if(verify==="dic"||verify==="subDic"){
                                $(this).parents(".dataLexiPanel").find(".lexiSelectCont").attr("lay-verify","required");
                            }
                        }
                    });

                    $("#tableId").val(result.data.tableId);
                    $("#alias").val(result.data.alias);
                    var mainData = result.data.mainFields;
                    var subData = result.data.subFields;
                    permission = result.data.permission;
                    formTable = result.data.formTable;
                    var sysBusEvent = result.data.sysBusEvent;
                    if (sysBusEvent != null) {
                        jsPreScript = sysBusEvent.jsPreScript;
                        jsAfterScript = sysBusEvent.jsAfterScript;
                    }

                    $(".selectorInfo").each(function () {
                        var inputObj = $(this).children();
                        if ($(this).children().attr("name") != undefined) {
                            var name = $(this).children().attr("name").split(":");
                            var selectorId = name[2] + "id";
                            inputObj.val(mainData[name[2].toLocaleLowerCase()]);
                            inputObj.attr("ids", mainData[selectorId.toLocaleLowerCase()]);
                        }
                    });
                    if (id) {
                        $(".temSelectCont").each(function () {
                            var value = $(this).attr("val");
                            $(this).val(value);
                        });

                        $("textarea[name^='m:'].textAreaInput").each(function () {
                            var value = $(this).text();
                            var reg=new RegExp("<br/>","g");
                            value = value.replace(reg,"\r\n");
                            $(this).text(value);
                        });

                        //富文本回显
                        $("div[name^='m:'].richTextCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find("textarea").text(mainData[fieldName.toLocaleLowerCase()]);
                        });

                        $(".radioOptionCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find('input:radio').each(function () {
                                    if ($(this).val() == mainData[fieldName.toLocaleLowerCase()]) {
                                        $(this).prop('checked', true);
                                    }
                                }
                            )
                        });
                        $(".checkOptionCont").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            $(this).find('input:checkbox').each(function () {
                                var fieldVal = mainData[fieldName.toLocaleLowerCase()];
                                if (fieldVal != null && fieldVal.indexOf($(this).val()) > -1) {
                                    $(this).prop("checked", true);
                                }
                            })
                        });

                        $("input[name^='m:'].dataLexiVal").each(function () {
                            var name = $(this).attr("name").split(":");
                            var fieldName = name[2];
                            if($(this).attr("dictype")==="0"){
                                $(this).parents(".lexiTree").next().find("option").each(function (ind,elem) {
                                    if($(elem).text() === mainData[fieldName]) {
                                        $(elem).attr("selected", true);
                                    }
                                });
                            }else{
                                $(this).prev().text(mainData[fieldName.toLocaleLowerCase()]);
                            }

                        });

                        $(".uploadFileList").each(function () {
                            var name = $(this).attr('name');
                            var fieldName = name.replace(/.*:/, '');
                            var flag = getUploadFileIsMain(subData, $(this));
                            if (flag) {
                                if (mainData[fieldName.toLocaleLowerCase()] != "" && mainData[fieldName.toLocaleLowerCase()] != undefined) {
                                    var fileIdArray = JSON.parse(mainData[fieldName.toLocaleLowerCase()]);
                                    if (fileIdArray.length > 0) {
                                        for (var i = 0; i < fileIdArray.length; i++) {
                                            var str = '<li fileId=' + fileIdArray[i]["fileid"] + '><p onclick="downFile(this)">' + fileIdArray[i]["name"] + '</p><i class="layui-icon layui-icon-delete deleteFile" ></i></li>';
                                            if (permission['field'][fieldName] == "r") {
                                                str = '<li fileId=' + fileIdArray[i]["fileid"] + '><p>' + fileIdArray[i]["name"] + '</p></li>';
                                            }
                                            $(this).append(str);
                                        }
                                    }
                                }
                            }
                        });

                        $(".uploadImgList").each(function () {
                            var name = $(this).attr('name');
                            var fieldName = name.replace(/.*:/, '');
                            var flag = getUploadFileIsMain(subData, $(this));
                            if (flag) {
                                if (mainData[fieldName.toLocaleLowerCase()] != "" && mainData[fieldName.toLocaleLowerCase()] != undefined) {
                                    var fileIdArray = JSON.parse(mainData[fieldName.toLocaleLowerCase()]);
                                    if (fileIdArray.length > 0) {
                                        for (var i = 0; i < fileIdArray.length; i++) {
                                            var str = '<li fileId=' + fileIdArray[i] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[i] + '" /></div><i class="layui-icon layui-icon-delete deleteFile" ></li>'
                                            if (permission['field'][fieldName] == "r") {
                                                str = '<li fileId=' + fileIdArray[i] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[i] + '" /></div></li>'
                                            }
                                            $(this).append(str);
                                        }
                                    }
                                }
                            }
                        });
                        if(enableEditPrivacy==0){
                            var dataPrivacyObj = $("select[name^='m:'][name$='dataPrivacyLevel']");
                            dataPrivacyObj.attr("disabled","disabled").css("pointer-events","none");
                        }
                        form.render();
                    }

                    //根据当前登录人密级查询表单密级列表
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        url: serverPath.systemPath + setter.sysLinkPath + "dictionary/listFilterByUserSecret",
                        data: {'nodeKey': 'sjmj'},
                        success: function (result) {
                            $("select[name='fileLevel']").html("");
                            $.each(result.data, function (index, objVal) {
                                //业务数据密级下拉框重新赋值
                                $("select[name^='m:'][name$='dataPrivacyLevel']").append("<option value=" + objVal.itemValue + ">" + objVal.itemName + "</option>");
                            });
                            $("select[name^='m:'][name$='dataPrivacyLevel']").val(1);

                            //新增初始化附件上传控件密级下拉框
                            var dataPrivacyObj = $("select[name^='m:'][name$='dataPrivacyLevel']");
                            fileLevelVal(dataPrivacyObj);

                            if (id) {
                                //业务数据密级赋值
                                $(".temSelectCont").each(function () {
                                    var value = $(this).attr("val");
                                    $(this).val(value);
                                });
                                //编辑时候附件上传控件密级下拉框根据业务数据展示对应密级选项
                                fileLevelVal(dataPrivacyObj);
                                //附件密级赋值
                                $(".uploadFileList").each(function () {
                                    var name = $(this).attr('name');
                                    var fieldName = name.replace(/.*:/, '');
                                    if (mainData[fieldName.toLocaleLowerCase()] != "" && mainData[fieldName.toLocaleLowerCase()] != undefined) {
                                        var fileIdArray = JSON.parse(mainData[fieldName.toLocaleLowerCase()]);
                                        if (fileIdArray.length > 0) {
                                            for (var i = 0; i < fileIdArray.length; i++) {
                                                $(this).prev().children("select").val(fileIdArray[i]["fileLevel"]);
                                            }
                                        }
                                    }
                                });
                                //子表附件密级赋值
                                for (var i = 0; i < subData.length; i++) {
                                    var subTableName = subData[i].tableName;
                                    var dataList = subData[i].dataList;
                                    var inputName = "s:" + subTableName;
                                    for (var j = 0; j < dataList.length; j++) {
                                        var trObjs = $("." + subTableName + " tr.temSpace");
                                        var jsonObj = dataList[j];
                                        for (var key in jsonObj) {
                                            var attrName = inputName + ":" + key;
                                            var ulObj = $(trObjs[j + 2]).children().find("ul[name='" + attrName + "']");
                                            var objVal = jsonObj[key];
                                            if (ulObj.length > 0) {
                                                var fileIdArray = JSON.parse(objVal);
                                                for (var g = 0; g < fileIdArray.length; g++) {
                                                    ulObj.prev().children("select").val(fileIdArray[g]["fileLevel"]);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            form.render();
                        }
                    });

                    //业务数据密级和附件密级联动设置  附件密级<=业务数据密级
                    addEditFileLevel();
                    function addEditFileLevel(){
                        var dataPrivacyObj = $("select[name^='m:'][name$='dataPrivacyLevel']");
                        fileLevelVal(dataPrivacyObj);
                        dataPrivacyObj.change(function(){
                            fileLevelVal(dataPrivacyObj);
                        })
                    }

                    //业务数据密级和附件密级联动设置
                    function fileLevelVal(obj){
                        $("select[name='fileLevel']").html("");
                        var privacyJson ={};
                        $("select[name^='m:'][name$='dataPrivacyLevel'] option").each(function () {
                            var privacyVal = $(this).val();
                            var privacyText = $(this).text();
                            privacyJson[privacyVal]=privacyText;
                        })
                        var selVal = obj.val();
                        for(var j=1;j<=selVal;j++){
                            $("select[name='fileLevel']").append("<option value=" + j + ">" + privacyJson[j] + "</option>");
                        }
                        form.render();
                    }

                    if (subData) {
                        processSubData(subData);
                    }
                    temQuery.initTemEvent(defProps, serverPath, setter);



                    $("input[name^='m:'].dataLexiVal").each(function () {
                        var name = $(this).attr("name").split(":");
                        var fieldName = name[2];
                        if($(this).attr("dictype")==="0"){
                            $(this).parents(".lexiTree").next().find("option").each(function (ind,elem) {
                                if($(elem).text() === mainData[fieldName]) {
                                    $(elem).attr("selected", true);
                                }
                            });
                        }
                    });
                    if (subData) {
                        for (var i = 0; i < subData.length; i++) {
                            var subTableName = subData[i].tableName;
                            var dataList = subData[i].dataList;
                            var inputName = "s:" + subTableName;
                            for (var j = 0; j < dataList.length; j++) {
                                var trObjs = $("." + subTableName + " tr.temSpace");
                                var jsonObj = dataList[j];
                                for (var key in jsonObj) {
                                    var attrName = inputName + ":" + key;
                                    var inputObj = $(trObjs[j + 2]).children().find("input[name='" + attrName + "']");
                                    var objVal = jsonObj[key];

                                    if (inputObj.length > 0) {
                                        if (inputObj.hasClass("dataLexiVal")) {
                                            if(inputObj.attr("dictype")==="0"){
                                                inputObj.parents(".lexiTree").next().find(".lexiSelectCont option").each(function (ind,elem) {
                                                    if($(elem).text() === objVal) {
                                                        $(elem).attr("selected", true);
                                                    }
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    form.render();
                } else {
                    window.parent.layer.alert(result.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert("预览失败！" + XMLHttpRequest.status);
            }
        });

        form.verify({
            required: function (value, item) {
                var tr = $(item).parents("tr");
                if(tr.hasClass("subContTem")){
                }else{
                    var fieldValue = $(item).val();
                    if (fieldValue == "") {
                        return '必填项不能为空';
                    }
                }
            },
            number: function (value, item) {
                var fieldValue = $(item).val();
                if (fieldValue != "") {
                    if (!(/^-?[0-9]+([.]{1}[0-9]+){0,1}$/.test(fieldValue))) {
                        return '只能填写数字';
                    }
                }
            },
            dic: function (value, item) {
                var fieldName = $(item).attr('name').split(":")[2];
                var dictype = $(item).attr('dictype');
                var isTrue = false;
                if(dictype==="1"){
                    $.each(formTable['fieldList'],function(index,element){
                        if(element["fieldName"]===fieldName){
                            if(element["isRequired"]===1){
                                isTrue = true;
                            }
                        }
                    });
                    if (permission['field'][fieldName] == "b"||isTrue) {//数据字典必填
                        var fieldValue = $(item).prev().text();
                        if (fieldValue == "请选择"||fieldValue=="") {
                            $(item).parent().css({"border": "1px solid #FF5722"});
                            return '必填项不能为空';
                        }else{
                            $(item).parent().css({"border": ""});
                        }
                    }
                }
            },
            checkRadio: function (value, item) {
                var radioName = $(item).parent().parent().attr('name').split(":");
                var radioFieldName = radioName[2];
                var isRequired = false;
                $.each(formTable['fieldList'],function(index,element){
                    if(element["fieldName"]===radioFieldName){
                        if(element["isRequired"]===1){
                            isRequired = true;
                        }
                    }
                });
                if (permission['field'][radioFieldName] == "b"||isRequired) {
                    var verifyElem = $(item).parent().parent().find('input');
                    var isTrue = false;
                    for (var k = 0; k < verifyElem.length; k++) {
                        isTrue = $(verifyElem[k]).is(':checked');
                        if (isTrue) {
                            break;
                        }
                    }
                    if (!isTrue) {
                        $(item).parent().parent().css({"border": "1px solid #FF5722"});
                        return '必填项不能为空';
                    }else{
                        $(item).parent().parent().css({"border": ""});
                    }
                }
            },
            imageAndFile: function (value, item) {
                var fieldName = $(item).attr('name').split(":")[2];
                var isRequired = false;
                $.each(formTable['fieldList'],function(index,element){
                    if(element["fieldName"]===fieldName){
                        if(element["isRequired"]===1){
                            isRequired = true;
                        }
                    }
                });
                if (permission['field'][fieldName] == "b"||isRequired) {
                    var children = $(item).children();
                    if (children.length == 0) {
                        $(item).parent().css({"border": "1px solid #FF5722"});
                        return '必填项不能为空';
                    }else{
                        $(item).parent().css({"border": ""});
                    }
                }
            },
            subDic: function (value, item) {

                var tr = $(item).parents("tr");
                if(tr.hasClass("subContTem")){
                }else{
                    var fieldName = $(item).attr('name').split(":")[2];
                    var dictype = $(item).attr('dictype');
                    var isRequired = false;
                    if(dictype==="1"){
                        $.each(formTable['subTableList'],function(index,element){
                            $.each(element["fieldList"],function(idx,ele){
                                if(ele["fieldName"]===fieldName){
                                    if(ele["isRequired"]===1){
                                        isRequired = true;
                                    }
                                }
                            });
                        });
                        if (permission['table'][fieldName] == "b"||isRequired) {
                            var fieldValue = $(item).prev().text();
                            if (fieldValue == "请选择"||fieldValue=="") {
                                $(item).parent().css({"border": "1px solid #FF5722"});
                                return '必填项不能为空';
                            }else{
                                $(item).parent().css({"border": ""});
                            }
                        }
                    }
                }
            },
            subCheckRadio: function (value, item) {

                var tr = $(item).parents("tr");
                if(tr.hasClass("subContTem")){
                }else{
                    var radioName = $(item).parent().parent().attr("name").split(":");
                    var radioFieldName = radioName[2];
                    var isRequired = false;
                    $.each(formTable['subTableList'],function(index,element){
                        $.each(element["fieldList"],function(idx,ele){
                            if(ele["fieldName"]===radioFieldName){
                                if(ele["isRequired"]===1){
                                    isRequired = true;
                                }
                            }
                        });
                    });
                    if (permission['table'][radioFieldName] == "b"||isRequired) {
                        var verifyElem = $(item).parent().parent().find('input');
                        var isTrue = false;
                        for (var k = 0; k < verifyElem.length; k++) {
                            isTrue = $(verifyElem[k]).is(':checked');
                            if (isTrue) {
                                break;
                            }
                        }
                        if (!isTrue) {
                            $(item).parent().parent().css({"border": "1px solid #FF5722"});
                            return '必填项不能为空';
                        }else{
                            $(item).parent().parent().css({"border": ""});
                        }
                    }
                }

            },
            subImageAndFile: function (value, item) {
                var tr = $(item).parents("tr");
                if(tr.hasClass("subContTem")){
                }else{
                    var fieldName = $(item).attr('name').split(":")[2];
                    var isRequired = false;
                    $.each(formTable['subTableList'],function(index,element){
                        $.each(element["fieldList"],function(idx,ele){
                            if(ele["fieldName"]===fieldName){
                                if(ele["isRequired"]===1){
                                    isRequired = true;
                                }
                            }
                        });
                    });
                    if (permission['table'][fieldName] == "b"||isRequired) {
                        var children = $(item).children();
                        if (children.length == 0) {
                            $(item).parent().css({"border": "1px solid #FF5722"});
                            return '必填项不能为空';
                        }else{
                            $(item).parent().css({"border": ""});
                        }
                    }
                }

            }
        });

        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });

        var index = parent.layer.getFrameIndex(window.name);
        $('.return').click(function () {
            parent.layer.close(index);
        });

        form.on('submit(dataTemplateForm)', function (data) {
            if (jsPreScript != null && jsPreScript != '') {
                var jsPreReturn = new Function(jsPreScript)();
                if (!jsPreReturn) {
                    return false;
                }
            }
            data.field.formData = getData();
            $.ajax({
                url: serverPath.formPath + setter.formLinkPath + "formHandler/add",
                type: "POST",
                dataType: 'json',
                data: data.field,
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        window.parent.layer.alert(result.msg, function (thisIndex) {
                            parent.layui.table.reload('templateTable',
                                {
                                    page: {curr: 1}
                                });
                            parent.layui.totalFilter.init('templateTable');
                            commons._bulletWindow(thisIndex);
                            parent.layer.close(index);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            if (jsAfterScript != null && jsAfterScript != '') {
                                new Function(jsAfterScript)();
                            }
                            parent.reflashDateForm();
                        });
                    } else {
                        window.parent.layer.alert(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
            return false;
        });

        function getUploadFileIsMain(subData, obj) {
            var flag = true;
            for (var p = 0; p < subData.length; p++) {
                var subTableName = subData[p].tableName;
                var tableClass = "temTable " + subTableName + " subFormTable";
                if ($(obj).parents("table ." + tableClass).length > 0) {
                    flag = false;
                }
            }
            return flag;
        }
        function processSubData(subData) {
            for (var h = 0; h < subData.length; h++) {
                var subTableName = subData[h].tableName;
                var dataList = subData[h].dataList;
                for (var k = 0; k < dataList.length; k++) {
                    if (k > 0) {
                        var cloneTr = $("." + subTableName + " tr.temSpace");
                        var trLength = cloneTr.length;
                        $(cloneTr[trLength - 1]).clone().appendTo("." + subTableName);
                        var cloneTr = $("." + subTableName + " tr.temSpace");
                        var index = cloneTr.length-2;
                        $(cloneTr[cloneTr.length-1]).find("div.temTag").text(index);
                        var radioDiv = $(cloneTr[cloneTr.length-1]).find("div.radioOptionCont");
                        radioDiv.find('input:radio').each(function () {
                            var attrName = $(this).attr("name");
                            var indexStr = "_"+(index-1).toString();
                            var newIndexStr = "_"+index.toString();
                            if(attrName.indexOf(indexStr) > -1){
                                attrName= attrName.replace(indexStr,newIndexStr);
                            }else{
                                attrName= attrName+newIndexStr;
                            }
                            $(this).attr("name",attrName);
                        })
                    }
                }
            }
            for (var i = 0; i < subData.length; i++) {
                var subTableName = subData[i].tableName;
                var dataList = subData[i].dataList;
                var inputName = "s:" + subTableName;
                for (var j = 0; j < dataList.length; j++) {
                    var trObjs = $("." + subTableName + " tr.temSpace");
                    var jsonObj = dataList[j];
                    for (var key in jsonObj) {
                        var attrName = inputName + ":" + key;
                        var inputObj = $(trObjs[j + 2]).children().find("input[name='" + attrName + "']");
                        var selectObj = $(trObjs[j + 2]).children().find("select[name='" + attrName + "']");
                        var divObj = $(trObjs[j + 2]).children().find("div[name='" + attrName + "']");
                        var ulObj = $(trObjs[j + 2]).children().find("ul[name='" + attrName + "']");
                        var objVal = jsonObj[key];
                        if (selectObj.length > 0) {
                            $(selectObj).val(objVal);
                        }
                        if (inputObj.length > 0) {
                            $(inputObj).val(objVal);
                            if (inputObj.hasClass("selectorInput")) {
                                var selectorId = key + "id";
                                inputObj.attr("ids", jsonObj[selectorId]);
                            }
                            if (inputObj.hasClass("dataLexiVal")) {
                                if(inputObj.attr("dictype")==="0"){
                                    //inputObj.parents(".temCont").find(".lexiSelectCont option:contains('"+objVal+"')").attr("selected",true);
                                    inputObj.parents(".lexiTree").next().find(".lexiSelectCont option").each(function (ind,elem) {
                                        if($(elem).text() === objVal) {
                                            $(elem).attr("selected", true);
                                        }
                                    });
                                }else{
                                    inputObj.prev().text(objVal);
                                }
                            }
                        }
                        if (ulObj.length > 0) {
                            var fileIdArray = JSON.parse(objVal);
                            for (var g = 0; g < fileIdArray.length; g++) {
                                var str = '<li fileId=' + fileIdArray[g]["fileid"] + '><p>' + fileIdArray[g]["name"] + '</p><i class="layui-icon layui-icon-delete deleteFile" ></i></li>';
                                if (ulObj.hasClass("uploadImgList")) {
                                    str = '<li fileId=' + fileIdArray[g] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[g] + '" /></div><i class="layui-icon layui-icon-delete deleteFile" ></li>'
                                }
                                if (permission['table'][key] == "r") {
                                    str = '<li fileId=' + fileIdArray[g]["fileid"] + '><p>' + fileIdArray[g]["name"] + '</p></li>';
                                    if (ulObj.hasClass("uploadImgList")) {
                                        str = '<li fileId=' + fileIdArray[g] + '><div class="fileByImg"><img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + fileIdArray[g] + '" /></div></li>'
                                    }
                                }
                                ulObj.append(str);
                            }
                        }
                        if (divObj.length > 0) {
                            divObj.find('input:checkbox').each(function () {
                                if (objVal != null && objVal.indexOf($(this).val()) > -1) {
                                    $(this).prop("checked", true);
                                }
                            });
                            divObj.find('input:radio').each(function () {
                                if ($(this).val() === objVal) {
                                    $(this).prop('checked', true);
                                }
                            })
                            //富文本
                            divObj.find('textarea').text(objVal);
                        }
                        var textareaObj = $(trObjs[j + 2]).children().find("textarea[name='" + attrName + "']");
                        var regExp=new RegExp("<br/>","g");
                        var textVal = objVal.replace(regExp,"\r\n");
                        $(textareaObj).val(textVal);
                    }
                }
            }
            form.render();
        }
        temQuery.initSubEvent(defProps, serverPath, setter);
        $.ajax({
            url: serverPath.formPath + setter.formLinkPath + 'formRule/getRuleByFormKey',
            dataType: 'json',
            data: {"formKey": formKey},
            success: function (result) {
                if (commons._filterRecord(result)) {
                    var ruleString = "layui.use('form',function(){"+
                        "var form = layui.form;"+
                            "form.render();"+
                        "form.verify({";
                    if(null != result.data){
                        for(var i=0;i<result.data.length;i++){
                            var ruleData = result.data[i];
                            ruleString += ruleData.alias+":function (value, item) {" +
                                "        if (value != '' && !(/" + ruleData.rule + "/.test(value))) {" +
                                "            return '" + ruleData.tipInfo + "';" +
                                "        }" +
                                "    },";
                        }
                        ruleString += "}); });";
                        if (result.data.length > 0) {
                            var ruleJs = new Function(ruleString)();
                            if (!ruleJs) {
                                return false;
                            }
                        }
                    }
                }else {
                    window.parent.layer.alert(result.msg);
                }
            }
        });



        })

            //按钮权限处理-根据权限继承字段
            setTimeout(function () {
                $(":button").each(function(){
                    if($(this).hasClass("temButton")){
                        var powerInherit = JSON.parse($(this).attr('dialoginstall')).powerInherit;
                        var inheritField = $("input[name$=':"+powerInherit+"']");
                        if(inheritField.length<=0){
                            $(this).css("display","none");
                        }
                        if(inheritField.attr("disabled")){
                            $(this).attr("disabled",true);
                        }
                    }
                })
            },1000)

</script>
<#if needHeadAndBottom != 'no'>
</body>
</html>
</#if>

